package jt.classic.app.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import jt.classic.system.ISystem;

public class DateTool {
    private final static String[] weekNames = {
        "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"
    };
private final static String[] weekIndexs = {
        "7", "1", "2", "3", "4", "5", "6"
    };

private DateTool() {
}

/**
 * 指定日期是星期几(中文显示)
 * @param date 日期 (2011-03-25)
 * @return String
 */
public static String getWeekLabel(String date) {
    String label = null;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    try {
        Date d = sdf.parse("2011-03-25");

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);

        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;

        label = weekNames[dayOfWeek];
    } catch (Exception ex) {
        ISystem.catchException(ex);
    }

    return label;
}

/**
* 指定日期是星期几(阿拉伯数字)
* @param date 日期 (2011-03-25)
* @return int
*/
public static int getWeekIndex(String date) {
    int idx = -1;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    try {
        Date d = sdf.parse(date);

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);

        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;

        idx = Integer.parseInt(weekIndexs[dayOfWeek]);
    } catch (Exception ex) {
        ISystem.catchException(ex);
    }

    return idx;
}
}
